package com.example.loginstarter.controller;


import com.example.loginstarter.domain.ResponseResult;
import com.example.loginstarter.service.LoginService;
import com.yc.yjh.entity.Users;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;


@RestController
@RequestMapping("/user")
public class UserController {
    @Resource
    private LoginService loginService;
    @RequestMapping("login")
    public ResponseResult login(@RequestBody Users user){
        return loginService.login(user);
    }

    @RequestMapping("logout")
    public ResponseResult logout(){
        return loginService.logout();
    }

    @RequestMapping("getUserInfo")
    public ResponseResult getUserInfo(HttpServletRequest request){
        return loginService.getUserInfo(request);
    }
    @RequestMapping("hello")
    @PreAuthorize("hasAnyAuthority('test')")
    public String hello(){
        return "hello";
    }

}
